package Com.HupochuanAdmin.Dal.Tab;

import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import Com.Hupochuan.Dal.DBManager.DBManager;
import Com.Hupochuan.Vo.Type;

public class TypeTab {
	/*
	 * 本类私有对象
	 */
	private DBManager<Type> dbManager = new DBManager<Type>(Type.class);
	
	/*
	 * 单一实例
	 */
	private TypeTab(){}
	private static TypeTab typeTab = new TypeTab();
	public static TypeTab getObject(){
		return typeTab;
	}
	
	/*
	 * 获得类型列表
	 */
	public List<Type> findTypeList(){
		//参数部分
		List<Type> typeList = new Vector<Type>();
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" select Type.*,( ");
		sqlBuff.append(" 	select count(id) from MovieType ");
		sqlBuff.append(" 	where typeId=Type.id ");
		sqlBuff.append(" ) as movieCount ");
		sqlBuff.append(" from Type ");
		sqlBuff.append(" order by weight desc,id ");
		
		//执行sql 
		typeList = this.dbManager.querySqlReturnVoList(sqlBuff.toString(), paraHash);
		
		//返回列表
		return typeList;
	}
	
	/*
	 * 获得类型ID
	 */
	public long findTypeId(String name){
		//参数部分
		long typeId = 0;
		StringBuffer sqlBuff = new StringBuffer();
		Hashtable<String,Object> paraHash = new Hashtable<String,Object>();
		
		//sql语句部分
		sqlBuff.append(" select id from Type where name=${name} ");
		
		//sql参数部分
		paraHash.put("name",name);

		//执行sql
		typeId = dbManager.querySqlReturnLong(sqlBuff.toString(), paraHash);
		
		//返回
		return typeId;
	}
}
